<?php
require_once('../config/auth.php');
require_once('guardUnit.cl.php');
$__CURRENT_PAGE__ = 'garde_unite';
$__TITLE__ = "Formulaire d'ajouter une unité de garde";
$guardUnit = new GuardUnit();
$message = '';
if(count($_POST) > 0 ) {
  $guardUnitData = $guardUnit->save($_POST);
    if(!$guardUnit->hasError()) {
        $message = "<div class='alert alert-success'>Departement sauvegardés avec succès</div>";
    }
}
elseif(!empty($_GET['id'])) {
    $guardUnit->loadGuardUnitById($_GET['id']);
}
require_once(dirname(__FILE__).'/../config/head.php'); 
 ?>
<body>
<?php require_once(dirname(__FILE__).'/../config/menu.php'); ?>
<div class="container">
 <h1>Ajouter une unité de garde</h1>
 <?php echo $message ?>
 <form method="post" class="form">
  <input type="hidden" name="id" value="<?php echo $guardUnit->getId() ?>" />
  <div class="row">
    <div class="span4">
      <label>Libellé:</label>
      <input type="text" name="label" size="50" maxlength="50" value="<?php echo $guardUnit->getLabel() ?>">
      <?php echo $guardUnit->getError('label') ?>
    </div>
    <div class="span4">  
      <label>Type:</label>
        <select name="type">
            <option value="">Tous les types</option>
            <option <?php echo ($guardUnit->getType()==GuardUnit::WEEK)  ? 'selected="selected"' : '' ?> value="<?php echo GuardUnit::WEEK ?>">Semaines</option>
            <option <?php echo ($guardUnit->getType()==GuardUnit::WEEKEND)  ? 'selected="selected"' : '' ?> value="<?php echo GuardUnit::WEEKEND ?>">Weekends</option>
            <option <?php echo ($guardUnit->getType()==GuardUnit::NATHOLIDAY)  ? 'selected="selected"' : '' ?> value="<?php echo GuardUnit::NATHOLIDAY?>">Fêtes nationales</option>
            <option <?php echo ($guardUnit->getType()==GuardUnit::RELHOLIDAY)  ? 'selected="selected"' : '' ?> value="<?php echo GuardUnit::RELHOLIDAY?>">Fêtes religieuses</option>
        </select>
        <?php echo $guardUnit->getError('type') ?>  
    </div>    
  </div>

  <div class="row">
        <div class="input-append span3 datepicker date" data-date="<?php echo $startDate ?>" data-date-format="yyyy-mm-dd">
            <label>Date de début</label>
            <input class="span2" size="16" type="text" name="start_date" value="<?php echo $guardUnit->getStartDate() ?>">
            <?php echo $guardUnit->getError('start_date') ?>
            <span class="add-on"><i class="icon-th"></i></span>
        </div>

        <div class="input-append span3 datepicker date" data-date="<?php echo $endtDate ?>" data-date-format="yyy-mm-dd">
            <label>Date de fin</label>
            <input class="span2" size="16" type="text" name="end_date" value="<?php echo $guardUnit->getEndDate() ?>">
            <?php echo $guardUnit->getError('end_date') ?>
            <span class="add-on"><i class="icon-th"></i></span>
        </div>
  </div>

  <div class="row">
     <div class="span2">
         <input type="reset" value="Annuler" class="btn btn-large btn-block">
     </div>
     <div class="span2 offset3">
         <input type="submit" value="Valider" class="btn btn-success btn-large btn-block">
     </div>
 </div>
 </form>
</div> 
</body>
